<!DOCTYPE html>

<html>
<head>
  <title>walker.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="browser.html">
                browser.js
              </a>
            
              
              <a class="source" href="functions.html">
                functions.js
              </a>
            
              
              <a class="source" href="index.html">
                index.js
              </a>
            
              
              <a class="source" href="parser.html">
                parser.js
              </a>
            
              
              <a class="source" href="symtab.html">
                symtab.js
              </a>
            
              
              <a class="source" href="tokenizer.html">
                tokenizer.js
              </a>
            
              
              <a class="source" href="walker.html">
                walker.js
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>walker.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              
            </div>
            
            <div class="content"><div class='highlight'><pre><span class="keyword">var</span> _ = require(<span class="string">'./helper/util'</span>);

<span class="keyword">var</span> Walker = <span class="keyword">function</span>(){

}


Walker.prototype = {
    constructor: Walker,
    walk: <span class="keyword">function</span>(node){
        <span class="keyword">if</span>(Array.isArray(node)){
            <span class="keyword">return</span> <span class="keyword">this</span>._walkArray(node);
        }<span class="keyword">else</span>{
            <span class="keyword">return</span> <span class="keyword">this</span>._walk(node);
        }
    },
    walk_defaut: <span class="keyword">function</span>(node){
        <span class="keyword">if</span>(node.list || node.body){
            <span class="keyword">return</span> <span class="keyword">this</span>.walk(node.list || node.body);
        }<span class="keyword">else</span> <span class="keyword">if</span>(node.type &amp;&amp; <span class="keyword">this</span>.walk_token){
            <span class="keyword">return</span> <span class="keyword">this</span>.walk_token(node)
        }<span class="keyword">else</span>{
            console.error(<span class="string">'no "'</span> + <span class="keyword">this</span>._inspect(node) + <span class="string">'" walk defined'</span>);
        }
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <p>walk<em>token: function(tree){
    throw Error(&#39;walk_token must be realized&#39;);
    // </em>.log(&#39;walk token: &#39; + this._inspect(node));</p>
<p>},</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    _walkArray: <span class="keyword">function</span>(nodes){
        <span class="keyword">var</span> self = <span class="keyword">this</span>;
        <span class="keyword">var</span> res = [];
        nodes.forEach(<span class="keyword">function</span>(node){
            <span class="keyword">if</span>(node) res.push(self._walk(node));
        })
        <span class="keyword">return</span> res;
    },
    _walk: <span class="keyword">function</span>(node){
        <span class="keyword">var</span> sign = <span class="keyword">this</span>._inspect(node),
            name = <span class="string">'walk_'</span> + sign;</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <p>_.log(name,&#39;visit&#39;);</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span>(<span class="keyword">this</span>[name]) <span class="keyword">return</span> <span class="keyword">this</span>[name](node);
        <span class="keyword">else</span> <span class="keyword">return</span> <span class="keyword">this</span>.walk_defaut(node);
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-4">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-4">&#182;</a>
              </div>
              <p>inspect token or node</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    _inspect: <span class="keyword">function</span>(node){
        <span class="keyword">return</span> node.type? node.type.toLowerCase() : node.constructor.name.toLowerCase();
    },
    error: <span class="keyword">function</span>(e){
        <span class="keyword">throw</span> e
    }
}

module.exports = Walker;</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
